'use strict';

angular.module('hanxinBroker').directive('checkIsPersonalId', function twIsWord() {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function (scope, element, attrs, ngModel) {
      ngModel.$parsers.push(function (value) {
        if (_.isUndefined(value)) {
          return undefined;
        }

        var isPersonalId = /^(\d{15}$)|(^\d{17}([0-9]|X)$)/.test(value);
        ngModel.$setValidity('personalId', isPersonalId);

        return isPersonalId ? value : undefined;
      });
    }
  };
});
